package com.baiyi.homeui.hshomeui;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.FragmentActivity;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;

import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.VideoView;

import com.baiyi.homeui.hshomeui.callback.IOnPcControlCallBack;
import com.baiyi.homeui.hshomeui.databinding.ActivityMainBinding;
import com.baiyi.homeui.hshomeui.entity.Disk;
import com.baiyi.homeui.hshomeui.entity.Fan;
import com.baiyi.homeui.hshomeui.entity.FanLCD;
import com.baiyi.homeui.hshomeui.entity.PcCpu;
import com.baiyi.homeui.hshomeui.entity.PcGpu;
import com.baiyi.homeui.hshomeui.entity.PcInfo;
import com.baiyi.homeui.hshomeui.entity.PcMd;
import com.baiyi.homeui.hshomeui.entity.PcMem;
import com.baiyi.homeui.hshomeui.entity.PcNetwork;
import com.baiyi.homeui.hshomeui.entity.PmSetting;
import com.baiyi.homeui.hshomeui.entity.ScreenConfig;
import com.baiyi.homeui.hshomeui.manage.MsgReceiverManager;
import com.baiyi.homeui.hshomeui.manage.SerialDataManage;
import com.baiyi.homeui.hshomeui.tv.RogTextview;
import com.baiyi.homeui.hshomeui.tv.TradeTextview;
import com.baiyi.homeui.hshomeui.util.FileUtil;
import com.baiyi.homeui.hshomeui.util.JsonUtils;
import com.baiyi.homeui.hshomeui.util.SLog;
import com.baiyi.homeui.hshomeui.util.ScreenController;
import com.baiyi.homeui.hshomeui.util.SpUtils;
import com.baiyi.homeui.hshomeui.util.Util;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.JsonParser;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class MainActivity extends FragmentActivity implements IOnPcControlCallBack {

    private FullScreenVideoView main_video1, main_video2, standby_video;
    private String TAG = "HSMainActivity";
    private ActivityMainBinding mainBinding;
    private final int MSG_REFRESH_UI = 101;
    private final int MSG_HANDEL_MEDIA = 102;
    private final int MSG_HANDEL_MEDIA2 = 117;
    private final int MSG_INIT_SERVICE = 103;
    private final int MSG_REFRESH_SHOWINFO = 104;
    private final int MSG_REFRESH_CONFIG = 105;
    private final int MSG_REFRESH_BRIGIESS = 106;
    private final int MSG_REFRESH_BLOCKSCREEN = 107;
    private final int MSG_REFRESH_POWER = 108;
    private final int MSG_REFRESH_FILE = 109;

    private final int MSG_CHECKUPDATE = 110;

    private final int MSG_DISSCONNECT = 111;

    private final int MSG_RECONNECT = 112;

    private final int MSG_CONNECTED = 113;

    private final int MSG_PRESET_CONFIG = 114;
    private final int MSG_NAME_CHANGE = 115;

    private final int MSG_WATERFALLMODE_CHANGE = 116;
    private final String ACTION_CHECKLOCAL_UPDATE = "com.baiyi.action.systemupdate.checklocal";
    private int saveBright = 125;
    private String[] defultConfig = new String[]{"Cpu Usage", "Gpu Usage", "Date&Time"};
    public Map<String, Float> speedMap = new HashMap<>();

    private boolean waterBlockScreen = true;

    private String mCpuName, mGpuName;
    private ScreenConfig config;

    private ScreenController screenController;

    private boolean isScreenOn = true;//屏幕亮起

    private HashMap<String,String> subTitle = new HashMap<>();
    private String[] monthS = new String[]{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep"
            ,"Oct","Nov","Dec"};
//    :Mon.、Tue.(或Tues.)、Wed.、Thu.(或Thur./Thurs.)、Fri.、Sat.、Sun.
    private String[] weeks = new String[]{"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
    private Handler mainHandler = new Handler(Looper.myLooper()) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MSG_REFRESH_UI:


                    SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");
                    SimpleDateFormat sdfs = new SimpleDateFormat("HH:mm");
                    SimpleDateFormat sdfss = new SimpleDateFormat("ss");

                    setInfoValue("Date",sdf.format(System.currentTimeMillis()),"");
                    setInfoValue("Time",sdfs.format(System.currentTimeMillis()),"");
                    setInfoValue("Date&Time",sdfs.format(System.currentTimeMillis()),sdfss.format(System.currentTimeMillis()));

                    PcInfo pcInfo = (PcInfo) msg.obj;
                    PcCpu cpu = pcInfo.getCpu();
                    PcMem mem = pcInfo.getMemory();
                    PcMd md = pcInfo.getMotherboard();
                    PcNetwork network = pcInfo.getNetwork();
                    Disk disk = pcInfo.getDisk();
                    PcGpu gpu = pcInfo.getGpu();
                    ArrayList<Fan> fans = pcInfo.getFans();

                    long time = pcInfo.getTimestamp();
                    long deviceTime = System.currentTimeMillis();
                    long chaTime;
                    if (deviceTime < time) {
                        chaTime = time - deviceTime;
                    } else {
                        chaTime = deviceTime - time;
                    }

                    if (chaTime > 5 * 60 * 1000) {
                        Util.setAndroidSystemTime(MainActivity.this, time);
                    }
                    SLog.d(TAG,"配置信息"+new Gson().toJson(infoMap));
                    if (cpu != null) {
                        setFanSpeed((int) cpu.getTemperature());

                        setInfoValue("CPU Load",cpu.getLoad()+"","%");
                        setInfoValue("CPU Temperature",cpu.getTemperature()+"","°C");
                        setInfoValue("CPU Speed Average",cpu.getSpeedAverage()+"","MHZ");
//                        setInfoValue("CPU Power",cpu.getPower()+"");
                        setInfoValue("CPU Voltage",cpu.getVoltage()+"","V");

                    }

                    if (gpu != null) {
                        /*`GPU Temperature`：GPU温度
                                - `GPU Load`：GPU负载
                                - `GPU Fan`：GPU风扇
                                - `GPU Speed`：GPU速度
                                - `GPU Power`：GPU电源
                                - `GPU Voltage`：GPU电压*/
                        setInfoValue("GPU Load",gpu.getLoad()+"","%");
                        setInfoValue("GPU Temperature",gpu.getTemperature()+"","°C");
//                        setInfoValue("GPU Fan",gpu.getSpeed()+"");
                        setInfoValue("GPU Power",gpu.getPower()+"","°C");
                        setInfoValue("GPU Speed",gpu.getSpeed()+"","MHZ");
                        setInfoValue("GPU Voltage",gpu.getVoltage()+"","V");

                    }

                    if (disk != null) {
                        setInfoValue("Hard Disk Temperature",disk.getTemperature()+"","°C");

                    }
                    if (mem != null) {
                        setInfoValue("Memory Utilization",mem.getLoad()+"","%");
                        setInfoValue("Memory Frequency",mem.getSpeed()+"","MHZ");

                    }
                    if (md != null) {
                        setInfoValue("Motherboard Temperature",md.getTemperature()+"","°C");
                    }


                    /*if (!TextUtils.isEmpty(MsgReceiverManager.temp_unit)) {
                        String showunit = mainBinding.tvUnit1.getText().toString();
                        SLog.i(TAG, "temp_unit---" + MsgReceiverManager.temp_unit + "--showunit--" + showunit);
                        if (MsgReceiverManager.temp_unit.equals("Fahrenheit") && showunit.equals("°C")) {
                            mainBinding.tvUnit1.setText("℉");

                        } else if (MsgReceiverManager.temp_unit.equals("Celsius") && showunit.equals("℉")) {
                            mainBinding.tvUnit1.setText("°C");

                        }

                    }*/

                    break;
                case MSG_HANDEL_MEDIA:
                    if (TextUtils.isEmpty(playMode1) || media1.size() == 0) {
                        SLog.d(TAG, "playMode--null");
                        return;
                    }
                    if (playMode1.equals("Single")) {
                        setLayout1Path(basePath + media1.get(0));
                    } else if (playMode1.equals("Random")) {
                        //随机播放
                        Random random = new Random();
                        int randomN ;
                        do {
                            randomN = random.nextInt(media1.size());
                        } while (randomN == showNum); // 确保不等于10
                        showNum = randomN;
                        SLog.d(TAG,"Random showNum=="+showNum);
                        setLayout1Path(basePath + media1.get(showNum));

                    } else if (playMode1.equals("Cycle")) {
                        showNum++;
                        if (showNum >= media1.size()) {
                            showNum = 0;
                        }
                        setLayout1Path(basePath + media1.get(showNum));
                    }
                    break;
                case MSG_HANDEL_MEDIA2:
                    if (TextUtils.isEmpty(playMode2) || media2.size() == 0) {
                        SLog.d(TAG, "playMode2--null");
                        return;
                    }
                    if (playMode2.equals("Single")) {
                        setLayout2Path(basePath + media2.get(0));
                    } else if (playMode2.equals("Random")) {
                        //随机播放
                        Random random = new Random();
                        int randomN ;
                        do {
                            randomN = random.nextInt(media2.size());
                        } while (randomN == showNum2);
                        showNum2 = randomN;
                        SLog.d(TAG,"Random showNum=="+showNum2);
                        setLayout2Path(basePath + media2.get(showNum2));

                    } else if (playMode2.equals("Cycle")) {
                        showNum2++;
                        if (showNum2 >= media2.size()) {
                            showNum2 = 0;
                        }
                        setLayout2Path(basePath + media2.get(showNum2));
                    }
                    break;
                case MSG_INIT_SERVICE:
//                    Settings.System.putLong(getContentResolver(),
//                            android.provider.Settings.System.SCREEN_OFF_TIMEOUT,3*60*60*1000);
                    saveBright = SpUtils.getInstance().getBrightnessValue(MainActivity.this);
                    //Util.changeAppBrightness(saveBright,MainActivity.this);
                    setLayout1Path(defaultPath);
                    //setLayout2Path(path2);
                    SerialDataManage.getInstance().init(MainActivity.this);
                    SerialDataManage.getInstance().setOnServicesConnected(new SerialDataManage.OnServicesConnected() {
                        @Override
                        public void connected() {
                            MsgReceiverManager.getInstance().init(MainActivity.this,
                                    MainActivity.this);
                        }
                    });

//                    showStandby();
                    SLog.i(TAG, "250225");
                    screenController = new ScreenController(MainActivity.this);
                    /*String content = "{\"id\":\"Customization\",\"screenMode\":\"Screen Splitting\",\"playMode\":\"Single\",\"media\":[\"img1.jpg\",\"img1.jpg\"],\"sysinfoDisplay\":[[\"CPU Temperature\",\"GPU Temperature\",\"CPU Frequency\"],[\"CPU Usage\",\"GPU Usage\",\"CPU Power\"]]}";
                    ScreenConfig configtest = JsonUtils.stringToObject(content,ScreenConfig.class);
                    screenConfigChange(configtest);*/

                    /*ArrayList<String> files = new ArrayList<>();
                    files.add("img1.jpg");
                    deletFile(files);*/
                    /*Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.baiyi.app.lcdtest");
                    startActivity(LaunchIntent);*/
                    //setFanSpeed(70);
                    break;
                case MSG_REFRESH_SHOWINFO:
                    goneAll();
                    ArrayList<String> arrayList = (ArrayList<String>) msg.obj;
                    showInfo(arrayList);
                    break;
                case MSG_REFRESH_CONFIG:
                    config = (ScreenConfig) msg.obj;
                    SLog.i(TAG, "config---" + config.toString());

                    if (TextUtils.isEmpty(config.getId())) {
                        SLog.i(TAG, "config---is empty");
                        return;
                    }
                    mainBinding.mainParent.setVisibility(View.INVISIBLE);
//                    mainBinding.imgAnimation.setImageResource(0);
                    //2240 1080
                    mainHandler.removeMessages(MSG_HANDEL_MEDIA);
                    mainHandler.removeMessages(MSG_HANDEL_MEDIA2);
                    if (config.getId().equals("Customization")) {
                        //{"id":"Customzation","screenMode":"Full Screen","ratio":"1:1","playMode":"Shuffle","media":["2023-12-31_17-03-43.png"],"sysinfoDisplay":["CPU Temperature","CPU Frequency","CPU Usage"]}
                        // 获取当前LayoutParams
                        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) mainBinding.mainParent.getLayoutParams();


                        if (config.getScreenMode().equals("Full Screen")) {
                            media1 = (ArrayList<String>) config.getMeida();
                            playMode1 = (String) config.getPlayMode();
                            SLog.i(TAG, "config---Full Screen");
                            if (!TextUtils.isEmpty(config.getRatio())) {
                                SLog.i(TAG, "config---Full Screen--" + config.getRatio());
                                switch (config.getRatio()) {
                                    case "1:1":
                                        layoutParams.width = 1120;
                                        layoutParams.height = 1080;
                                        break;
                                    case "2:1":
                                        layoutParams.width = screen_width;
                                        layoutParams.height = screen_height;
                                        break;
                                    case "3:2":
                                        layoutParams.width = 1620;
                                        layoutParams.height = 1080;
                                        break;
                                    case "4:3":
                                        layoutParams.width = 1440;
                                        layoutParams.height = 1080;
                                        break;
                                    case "16:9":
                                        layoutParams.width = 1920;
                                        layoutParams.height = 1080;
                                        break;
                                }
                            }
                            mainBinding.mainParent.setLayoutParams(layoutParams);
                            mainBinding.homeLayout2.setVisibility(View.GONE);

                            releaseVideo(main_video2);
                            showNum = 0;
                            mainHandler.sendEmptyMessage(MSG_HANDEL_MEDIA);

                            PmSetting setting = JsonUtils.stringToObject(new Gson().toJson(config.getSettings()), PmSetting.class);
                            setAnimation1(setting, config.getRatio());

                            if (setting != null) {
                                setInfoColor(setting.getTitleColor(),setting.getContentColor());

                            }



                            goneAll();
                            ArrayList<String> strs = (ArrayList<String>) config.getSysinfoDisplay();
                            SLog.i(TAG, "config--" + strs.toArray() + "--media--" + media1);
                            showInfo(strs);


                        } else {
                            SLog.i(TAG, "--media--Screen Splitting");
                            layoutParams.width = screen_width;
                            layoutParams.height = screen_height;
                            mainBinding.mainParent.setLayoutParams(layoutParams);
                            ArrayList<String> playmodes = (ArrayList<String>) config.getPlayMode();
                            playMode1 = playmodes.get(0);
                            playMode2 = playmodes.get(1);
                            SLog.i(TAG, "playMode1--" + playMode1 + "--playMode2--" + playMode2);
                            mainBinding.homeLayout2.setVisibility(View.VISIBLE);
                            ArrayList<ArrayList<String>> medias = (ArrayList<ArrayList<String>>) config.getMeida();
                            media1 = medias.get(0);
                            media2 = medias.get(1);
                            SLog.i(TAG, "media1--" + media1.size() + "--media2--" + media2.size());
                            if (media1.size() > 0) {
                                setLayout1Path(basePath + media1.get(0));
                            }else {
                                main_video1.setVisibility(View.INVISIBLE);
                                mainBinding.mainImg1.setVisibility(View.INVISIBLE);
                            }
                            if (media2.size() > 0) {
                                setLayout2Path(basePath + media2.get(0));
                            }else {
                                main_video2.setVisibility(View.INVISIBLE);
                                mainBinding.mainImg2.setVisibility(View.INVISIBLE);
                            }
                            ArrayList<String> strs = (ArrayList<String>) config.getSysinfoDisplay();
//                            PmSetting setting = (PmSetting) JsonUtils.stringToObject(new Gson().toJson(config.getSettings()), PmSetting.class);

                            goneAll();
                            showInfo(strs);

                            JsonParser parser = new JsonParser();
                            //JsonArray jsonArray = parser.parse((String) config.getSysinfoDisplay()).getAsJsonArray();
                            ArrayList<PmSetting> pmsettings = (ArrayList<PmSetting>) JsonUtils.stringToList(new Gson().toJson(config.getSettings()), PmSetting.class);
                            if (pmsettings.size() > 0) {

                                PmSetting setting = pmsettings.get(0);
                                if (setting != null) {
                                    setInfoColor(setting.getTitleColor(),setting.getContentColor());
                                }
                                setAnimation1(setting, "");
                                if (pmsettings.size() > 1) {
                                    PmSetting setting2 = pmsettings.get(1);
//                                    setAnimation2(setting2);
                                }

                            }


                        }

                    } else {
                        // 获取当前LayoutParams
                        releaseVideo(main_video2);
                        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) mainBinding.mainParent.getLayoutParams();
                        layoutParams.width = screen_width;
                        layoutParams.height = screen_height;
                        mainBinding.mainParent.setLayoutParams(layoutParams);
                        mainBinding.mainLayout1.setVisibility(View.VISIBLE);
                        mainBinding.homeLayout2.setVisibility(View.GONE);

                        media1 = new ArrayList<>();
                        playMode1 = null;
                        String id = config.getId();
                        String path = id.split(":")[1].trim().replace(" ", "_");
                        setLayout1Path(basevideoPath + path + ".mp4");

                        goneAll();
                        ArrayList<String> strs = (ArrayList<String>) config.getSysinfoDisplay();
                        if (strs != null) {
                            SLog.i(TAG, "config--" + strs.toArray() + "--media--" + media1);
                            showInfo(strs);
                        }
                        PmSetting setting = JsonUtils.stringToObject(new Gson().toJson(config.getSettings()), PmSetting.class);
                        if (setting != null) {

                            setInfoColor(setting.getTitleColor(),setting.getContentColor());

                        }
                        setAnimation1(setting, "");

                    }


                    break;
                case MSG_REFRESH_BRIGIESS:
                    int value = (int) msg.obj;
                    saveBright = value;
                    SpUtils.getInstance().saveIntValue(MainActivity.this, SpUtils.KEY_BRIGHTNESS, value);
                    Util.changeAppBrightness(value, MainActivity.this);
                    break;
                case MSG_REFRESH_BLOCKSCREEN:
                    boolean event = (boolean) msg.obj;
                    if (event) {
//                        saveBright = SpUtils.getInstance().getBrightnessValue(MainActivity.this);
                        SLog.i(TAG, "MSG_REFRESH_BLOCKSCREEN-1-" + saveBright);
                        isScreenOn = true;
                        /*if(!screenController.isScreenOn()){
                            screenController.acquireScreenWakeLock();
                        }*/
                        Util.changeAppBrightness(saveBright, MainActivity.this);
                    } else {
                        SLog.i(TAG, "MSG_REFRESH_BLOCKSCREEN-2-" + saveBright + "--isScreenOn--" + isScreenOn);
                        if (!isScreenOn) return;
                        isScreenOn = false;
                        int nowBri = Util.getScreenBrightness(MainActivity.this);
                        if (nowBri != 0) {
                            saveBright = nowBri;
                        }
                        /*if(screenController.isScreenOn()){
                            screenController.releaseScreenWakeLock();
                        }*/
                        Util.changeAppBrightness(0, MainActivity.this);
                    }
                    break;
                case MSG_REFRESH_POWER:
                    String powerEvent = (String) msg.obj;
                    SLog.i(TAG, "MSG_REFRESH_POWER---" + powerEvent + "--isScreenOn--" + isScreenOn);
                    if (powerEvent.equals("suspend")
                            || powerEvent.equals("shutdown")
                            || powerEvent.equals("lock-screen")) {
                        if (!isScreenOn) return;
                        isScreenOn = false;
                        int nowBri = Util.getScreenBrightness(MainActivity.this);
                        if (nowBri != 0) {
                            saveBright = nowBri;
                        }
                        if (MsgReceiverManager.getInstance().displayInSleep) {
                            showStandby();
                        } else {
                            SLog.i(TAG, "MSG_REFRESH_POWER-suspend--" + saveBright);
                            /*if(screenController.isScreenOn()){
                                screenController.releaseScreenWakeLock();
                            }*/
                            Util.changeAppBrightness(0, MainActivity.this);

                        }

                    } else if (powerEvent.equals("resume") || powerEvent.equals("unlock-screen")) {
                        SLog.i(TAG, "MSG_REFRESH_POWER-resume--" + saveBright);
                        /*if(!screenController.isScreenOn()){
                            screenController.acquireScreenWakeLock();
                        }*/
                        Util.changeAppBrightness(saveBright, MainActivity.this);
                        if (config != null) {
                            Message message = new Message();
                            message.what = MSG_REFRESH_CONFIG;
                            message.obj = config;
                            mainHandler.sendMessage(message);
                        }
                        isScreenOn = true;
                        hindStandby();
                    }

                    break;
                case MSG_DISSCONNECT:
                    SLog.i(TAG, "MSG_DISSCONNECT-isScreenOn-" + isScreenOn);
                    if (!isScreenOn) return;
                    isScreenOn = false;
                    int nowBri = Util.getScreenBrightness(MainActivity.this);
                    if (nowBri != 0) {
                        saveBright = nowBri;
                    }
                    SLog.i(TAG, "MSG_DISSCONNECT--" + saveBright);
                    if (MsgReceiverManager.getInstance().displayInSleep) {
                        showStandby();
                    } else {
                        /*if(screenController.isScreenOn()){
                            screenController.releaseScreenWakeLock();
                        }*/
                        Util.changeAppBrightness(0, MainActivity.this);
                    }
                    break;
                case MSG_RECONNECT:
                    isScreenOn = true;
                    SLog.i(TAG, "MSG_RECONNECT--" + saveBright);
                    /*if(!screenController.isScreenOn()){
                        screenController.acquireScreenWakeLock();
                    }*/
                    Util.changeAppBrightness(saveBright, MainActivity.this);
                    if (config != null) {
                        Message message = new Message();
                        message.what = MSG_REFRESH_CONFIG;
                        message.obj = config;
                        mainHandler.sendMessage(message);
                    }
                    hindStandby();
                    break;
                case MSG_REFRESH_FILE:
                    String path = (String) msg.obj;
                    setLayout1Path(path);
                    break;
                case MSG_CHECKUPDATE:
                    SLog.i(TAG, "MSG_CHECKUPDATE");
//                    sendBroadcast(new Intent(ACTION_CHECKLOCAL_UPDATE));
                    //sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED));
                    Intent intent = new Intent(ACTION_CHECKLOCAL_UPDATE);
                    intent.setComponent(new ComponentName("android.rockchip.update.service",
                            "android.rockchip.update.service.RKUpdateReceiver"));
                    // 启动发送广播
                    sendBroadcast(intent);
                    break;
                case MSG_CONNECTED:
                    isScreenOn = true;
                    /*if(!screenController.isScreenOn()){
                        screenController.acquireScreenWakeLock();
                    }*/
                    Util.changeAppBrightness(saveBright, MainActivity.this);
                    hindStandby();
                    break;
                case MSG_PRESET_CONFIG:
                    ScreenConfig presetConfig = (ScreenConfig) msg.obj;
                    config.setSysinfoDisplay(presetConfig.getSysinfoDisplay());
                    config.setSettings(presetConfig.getSettings());

//                    mainBinding.imgAnimation.setImageResource(0);
                    PmSetting setting = JsonUtils.stringToObject(new Gson().toJson(config.getSettings()), PmSetting.class);
                    if (setting != null) {
                        setInfoColor(setting.getTitleColor(),setting.getContentColor());

                    }
                    setAnimation1(setting, config.getRatio());


                    goneAll();
                    ArrayList<String> strs = (ArrayList<String>) config.getSysinfoDisplay();
                    if (strs != null) {
                        SLog.i(TAG, "config--" + strs.toArray() + "--media--" + media1);
                        showInfo(strs);
                    }

                    break;
                case MSG_NAME_CHANGE:
                    /*mainBinding.cpuName.setText(mCpuName);
                    mainBinding.gpuName.setText(mGpuName);

                    mainBinding.cpuName2.setText(mCpuName);
                    mainBinding.gpuName2.setText(mGpuName);*/
                    break;
                case MSG_WATERFALLMODE_CHANGE:

                    break;
            }
        }
    };


    private String basevideoPath = "sdcard/pcMedia/";

    private String defaultPath = "/system/media/video/default.mp4";
    //private String defaultPath = "/storage/emulated/0/pcMedia/default.mp4";
    private String stanbyPath = "/system/media/video/standby.mp4";
    private String basePath = "sdcard/pcMedia/";
    private int showNum = 0;
    private int showNum2 = 0;
    private ArrayList<String> media1;
    private ArrayList<String> media2;
    private String playMode1,playMode2;
    private PowerManager.WakeLock mWakelock;

    //以[RPM，TEMP]数组形式体现 [10，20],
    //[30，30],
    //[50，40],
    //[65，55]，
    //[80，70],
    //[90，100]
    private int[][] fanConfig = new int[][]{{0, 0}, {10, 20}, {30, 30}, {50, 40}, {65, 55}, {80, 70}, {90, 100}};
    private int screen_width, screen_height;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DisplayMetrics dm = new DisplayMetrics();//屏幕度量
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        screen_width = dm.widthPixels;//宽度
        screen_height = dm.heightPixels;//高度
        SLog.d(TAG, "--onCreate--");
        main_video1 = mainBinding.mainVideo1;
        main_video2 = mainBinding.mainVideo2;
        standby_video = mainBinding.standbyVideo;

//        String uri1 = "android.resource://" + getPackageName() + "/" + R.raw.video_zhijiao;
//        String uri2 = "android.resource://" + getPackageName() + "/" + R.raw.video636;

        //setLayout2Path(path2);
        Util.changeAppBrightness(50, MainActivity.this);
        showStandby();

        mainHandler.sendEmptyMessageDelayed(MSG_INIT_SERVICE, 10000);
        //mainHandler.sendEmptyMessageDelayed(MSG_CHECKUPDATE,60000);
        //showInfo(defultConfig);
        /*String fanSpeed = FileUtil.readFile(fanPath);
        SLog.d(TAG,"--fanSpeed--"+fanSpeed);
        FileUtil.writeData(fanPath,"55");*/

        PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);// init powerManager
        mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |
                PowerManager.SCREEN_DIM_WAKE_LOCK, "homeui:homeuiTag"); // this target for tell OS which app control screen

        mainBinding.goFactory.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.baiyi.app.factorymode");
                startActivity(LaunchIntent);
//                screenController.releaseScreenWakeLock();
                return false;
            }
        });
        speedMap.clear();
        speedMap.put("Low Speed", 0.4f);
        speedMap.put("Mid Speed", 0.6f);
        speedMap.put("High Speed", 0.8f);
        speedMap.put("Full speed", 1f);
        SLog.i(TAG, "250116");

        subTitle.put("CPU Load", "CPU");
        subTitle.put("CPU Temperature", "CPU");
        subTitle.put("CPU Speed Average", "CPU");
        subTitle.put("CPU Voltage", "CPU");

        subTitle.put("GPU Load", "GPU");
        subTitle.put("GPU Temperature", "GPU");
        subTitle.put("GPU Power", "GPU");
        subTitle.put("GPU Speed", "GPU");
        subTitle.put("GPU Voltage", "GPU");

        subTitle.put("Hard Disk Temperature", "Hard Disk Temperature");
        subTitle.put("Memory Utilization", "Memory Utilization");
        subTitle.put("Memory Frequency", "Memory Frequency");
        subTitle.put("Motherboard Temperature", "Motherboard");
        goneAll();
    }


    private String animRainPath = "/system/media/anim/rain.webp";
    private String animVaporPath = "/system/media/anim/vapor.webp";


    /*private void setAnimation(PmSetting setting) {
        if(setting==null){
            mainBinding.imgAnimation.setImageResource(0);
            return;
        }
        PmSetting.FilterBean filterBean = setting.getFilter();
        if(filterBean!=null&&!TextUtils.isEmpty(filterBean.getValue())){

            float alph = (float)filterBean.getOpacity()/(float)100;
            SLog.i(TAG,"setAnimation--alph--"+alph);
            PropertyValuesHolder alphaHolder = PropertyValuesHolder
                    .ofFloat("alpha", 1f,alph);
            ObjectAnimator.ofPropertyValuesHolder(mainBinding.imgAnimation, alphaHolder).setDuration(300).start();
            String path = "/system/media/anim/"+filterBean.getValue()+".webp";
            SLog.i(TAG,"setAnimation--path--"+path);
            int draw = R.drawable.rain;
            if(filterBean.getValue().equals("Smoke")){
                draw = R.drawable.smoke;
            }
            Glide.with(this)
                    .asDrawable()
                    .load(draw) // 假设webp_animation是一个WebP动画资源
                    .into(mainBinding.imgAnimation);

        }else {
            mainBinding.imgAnimation.setImageResource(0);
        }
    }*/


    private void setAnimation1(PmSetting setting, String ratio) {
        if (setting == null) {
            int draw = R.drawable.defult;
            Glide.with(this)
                    .asDrawable()
                    .load(draw) // 假设webp_animation是一个WebP动画资源
                    .into(mainBinding.imgAnimation1);
            return;
        }
        PmSetting.FilterBean filterBean = setting.getFilter();
        if (filterBean != null && !TextUtils.isEmpty(filterBean.getValue())) {
            mainBinding.imgAnimation1.setVisibility(View.VISIBLE);
            float alph = (float) filterBean.getOpacity() / (float) 100;
            SLog.i(TAG, "setAnimation--alph--" + alph);
            PropertyValuesHolder alphaHolder = PropertyValuesHolder
                    .ofFloat("alpha", 1f, alph);
            ObjectAnimator.ofPropertyValuesHolder(mainBinding.imgAnimation1, alphaHolder).setDuration(300).start();
            String path = "/system/media/anim/" + filterBean.getValue() + ".webp";
            SLog.i(TAG, "setAnimation--path--" + path);

            int draw = R.drawable.coverage;
            if (!TextUtils.isEmpty(ratio) && ratio.equals("1:1")) {
                draw = R.drawable.coverage;
            }

            if (filterBean.getValue().equals("Smoke")) {
                if (!TextUtils.isEmpty(ratio) && ratio.equals("1:1")) {
                    draw = R.drawable.coverage;
                } else {
                    draw = R.drawable.coverage;
                }
            }
            Glide.with(this)
                    .asDrawable()
                    .load(draw) // 假设webp_animation是一个WebP动画资源
                    .into(mainBinding.imgAnimation1);

        } else {
            mainBinding.imgAnimation1.setImageResource(0);
        }
    }

    private void setAnimation2(PmSetting setting) {
        if (setting == null) {
            mainBinding.imgAnimation2.setImageResource(0);
            return;
        }
        PmSetting.FilterBean filterBean = setting.getFilter();
        if (filterBean != null && !TextUtils.isEmpty(filterBean.getValue())) {

            float alph = (float) filterBean.getOpacity() / (float) 100;
            SLog.i(TAG, "setAnimation--alph--" + alph);
            PropertyValuesHolder alphaHolder = PropertyValuesHolder
                    .ofFloat("alpha", 1f, alph);
            ObjectAnimator.ofPropertyValuesHolder(mainBinding.imgAnimation2, alphaHolder).setDuration(300).start();
            String path = "/system/media/anim/" + filterBean.getValue() + ".webp";
            SLog.i(TAG, "setAnimation--path--" + path);
            int draw = R.drawable.coverage;
            if (filterBean.getValue().equals("Smoke")) {
                draw = R.drawable.coverage;
            }
            Glide.with(this)
                    .asDrawable()
                    .load(draw) // 假设webp_animation是一个WebP动画资源
                    .into(mainBinding.imgAnimation2);

        } else {
            mainBinding.imgAnimation2.setImageResource(0);
        }
    }

    private String fanPath = "/sys/bus/platform/drivers/lcd_fan/speed";
//    private float ratio = 0.6f;

    //(((temp cur- temp 1) / (temp 2 - temp 1)) * (rpm 2 - rpm 1) + rpm 1) * ratio
    private void setFanSpeed(int temp) {
        FanLCD fanLCD = MsgReceiverManager.getInstance().getFanLCD();
        SLog.i(TAG, "fanLCD---" + fanLCD.toString());
        if (fanLCD.getMode().equals("Smart Mode")) {

            //SLog.i(TAG,"speedMap---"+speedMap.size());
            //ratio = speedMap.get(fanLCD.getSpeed());
            ArrayList<ArrayList<Integer>> modeList = (ArrayList<ArrayList<Integer>>) fanLCD.getSmartMode();
            if (modeList != null) {
                fanConfig = Util.convertToIntArray(modeList);
            }
            int[] config1 = null;
            int[] config2 = null;
            for (int i = 0; i < fanConfig.length - 2; i++) {
                int[] config = fanConfig[i];
                int[] configadd1 = fanConfig[i + 1];
                if (config[0] == temp) {
                    config1 = config;
                } else if (config[0] < temp && configadd1[0] > temp) {
                    config1 = config;
                    config2 = configadd1;
                }
            }

            float speed = 0;
            if (config1 != null && config2 == null) {
                speed = config1[1];
            } else if (config1 != null && config2 != null) {
                //(((70 - 60)  (80  60)) * (80 - 60) + 6)*0.6
                SLog.i(TAG, "config1--" + config1[0] + "--" + config1[1]);
                SLog.i(TAG, "config2--" + config2[0] + "--" + config2[1]);
                float jisuan1 = ((float) (temp - config1[0]) / (float) (config2[0] - config1[0]));
                float jisuan2 = jisuan1 * (config2[1] - config1[1]) + config1[1];
//                SLog.i(TAG, "jisuan1---" + jisuan1);
//                SLog.i(TAG, "jisuan2---" + jisuan2);
                speed = jisuan2;

            }
            SLog.i(TAG, "setFanSpeed---" + ((int) speed));
            FileUtil.writeData(fanPath, ((int) speed) + "");
        } else {
            //ratio = speedMap.get(fanLCD.getSpeed());
            float speed = fanLCD.getFixedMode();
            SLog.i(TAG, "setFanSpeed---" + ((int) speed));
            FileUtil.writeData(fanPath, ((int) speed) + "");
        }

    }

    private void deletFile(ArrayList<String> fileList) {
        for (int i = 0; i < fileList.size(); i++) {
            String path = basePath + fileList.get(i);
            SLog.d(TAG, "---deletFile---" + path);
            File file = new File(path);
            if (file.exists()) {
                file.delete();
            } else {
                SLog.i(TAG, "deletFile FAIL nofund media");
            }
        }
    }

    private void setLayout1Path(String path) {
        File mediaFile = new File(path);
        SLog.i(TAG, "setLayout1Path--" + path);
        if (!mediaFile.exists()) {
            SLog.i(TAG, "file not found ,play next");
            mainHandler.sendEmptyMessage(MSG_HANDEL_MEDIA);
            return;
        }
        releaseVideo(main_video1);
        if (path.endsWith("mp4")) {
            main_video1.setVisibility(View.VISIBLE);
            mainBinding.mainImg1.setVisibility(View.GONE);
            main_video1.setVideoPath(path);
            main_video1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    SLog.i(TAG, "init_vieofile:..main_video1...视频准备完毕,可以进行播放....." + mediaPlayer.isPlaying());
                    if (!mediaPlayer.isPlaying()) {
                        mediaPlayer.start();
                    }

                    if (TextUtils.isEmpty(playMode1) || playMode1.equals("single")) {
                        mediaPlayer.setLooping(true);
                    }
                    if (mainBinding.mainParent.getVisibility() == View.GONE
                            || mainBinding.mainParent.getVisibility() == View.INVISIBLE) {
                        mainBinding.mainParent.setVisibility(View.VISIBLE);
                    }
                }
            });
            main_video1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    //结束播放
                    if (!TextUtils.isEmpty(playMode1) && !playMode1.equals("single")) {
                        mainHandler.sendEmptyMessage(MSG_HANDEL_MEDIA);
                    }
                }
            });

            main_video1.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mp, int what, int extra) {
                    SLog.i(TAG, "播放异常....." + extra + "--what==" + what);
                    main_video1.stopPlayback(); //播放异常，则停止播放，防止弹窗使界面阻塞
                    mainHandler.sendEmptyMessage(MSG_HANDEL_MEDIA);
                    return true;
                }
            });

        } else {
            main_video1.setVisibility(View.GONE);

            mainBinding.mainImg1.setVisibility(View.VISIBLE);
            Glide.with(MainActivity.this)
                    .load(path)
                    .into(mainBinding.mainImg1);
            if (!TextUtils.isEmpty(playMode1) && !playMode1.equals("single")) {
                mainHandler.sendEmptyMessageDelayed(MSG_HANDEL_MEDIA, 5000);
            }
            if (mainBinding.mainParent.getVisibility() == View.GONE || mainBinding.mainParent.getVisibility() == View.INVISIBLE) {
                mainBinding.mainParent.setVisibility(View.VISIBLE);
            }
        }
    }


    private void releaseVideo(VideoView videoView) {
        if (!videoView.isPlaying()) return;
        // 停止播放视频
        videoView.stopPlayback();

        // 释放VideoView
        videoView.setOnPreparedListener(null);
        videoView.destroyDrawingCache();
        videoView.suspend();
    }

    private void showStandby() {
        SLog.i(TAG, "--showStandby--");
        mainBinding.mainParent.setVisibility(View.INVISIBLE);
        goneAll();
        setAnimation1(null, "");
        setAnimation2(null);

        if (config != null) {
            ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) mainBinding.mainParent.getLayoutParams();
            layoutParams.width = screen_width;
            layoutParams.height = screen_height;
            mainBinding.mainParent.setLayoutParams(layoutParams);
        }
        Util.changeAppBrightness(50, MainActivity.this);
        standby_video.setVideoPath(stanbyPath);
        standby_video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                SLog.i(TAG, "init_vieofile:..standby_video...视频准备完毕,可以进行播放....." + !mediaPlayer.isPlaying());

                if (!mediaPlayer.isPlaying()) {
                    mediaPlayer.start();
                    mediaPlayer.setLooping(true);
                }

            }
        });
        mainBinding.layoutMdeia.setVisibility(View.GONE);
        mainBinding.homeLayout2.setVisibility(View.GONE);

        standby_video.setVisibility(View.VISIBLE);
        mainBinding.homeLayout1.setVisibility(View.VISIBLE);

        mainBinding.mainParent.setVisibility(View.VISIBLE);
    }

    private void hindStandby() {
        SLog.i(TAG, "hindStandby");
        if (standby_video.isPlaying()) {
            standby_video.pause();
            standby_video.suspend();
        }
        mainBinding.layoutMdeia.setVisibility(View.VISIBLE);
        standby_video.setVisibility(View.GONE);
    }

    private void setLayout2Path(String path) {
        File mediaFile = new File(path);
        if (!mediaFile.exists()) {
            SLog.i(TAG, "file not found ,play next2");
            mainHandler.sendEmptyMessage(MSG_HANDEL_MEDIA2);
            return;
        }
        SLog.i(TAG, "setLayout2Path--" + path);
        releaseVideo(main_video2);
        if (path.endsWith("mp4")) {
            main_video2.setVisibility(View.VISIBLE);
            mainBinding.mainImg2.setVisibility(View.GONE);
            main_video2.setVideoPath(path);
            main_video2.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    SLog.i(TAG, "init_vieofile:.....2视频准备完毕,可以进行播放....." + !mediaPlayer.isPlaying());

                    if (!mediaPlayer.isPlaying()) {
                        mediaPlayer.start();
                    }

                    if (TextUtils.isEmpty(playMode2) || playMode2.equals("single")) {
                        mediaPlayer.setLooping(true);
                    }

                    if (mainBinding.mainParent.getVisibility() == View.GONE ||
                            mainBinding.mainParent.getVisibility() == View.INVISIBLE) {
                        mainBinding.mainParent.setVisibility(View.VISIBLE);
                    }
                }
            });

            main_video2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    //结束播放
                    if (!TextUtils.isEmpty(playMode2) && !playMode2.equals("single")) {
                        mainHandler.sendEmptyMessage(MSG_HANDEL_MEDIA2);
                    }
                }
            });

            main_video2.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mp, int what, int extra) {
                    SLog.i(TAG, "播放异常....." + extra + "--what==" + what);
                    main_video2.stopPlayback(); //播放异常，则停止播放，防止弹窗使界面阻塞
                    mainHandler.sendEmptyMessage(MSG_HANDEL_MEDIA2);
                    return true;
                }
            });


        } else {
            main_video2.setVisibility(View.GONE);

            mainBinding.mainImg2.setVisibility(View.VISIBLE);
            Glide.with(MainActivity.this)
                    .load(path)
                    .into(mainBinding.mainImg2);

            if (!TextUtils.isEmpty(playMode2) && !playMode2.equals("single")) {
                mainHandler.sendEmptyMessageDelayed(MSG_HANDEL_MEDIA2, 5000);
            }
            if (mainBinding.mainParent.getVisibility() == View.GONE || mainBinding.mainParent.getVisibility() == View.INVISIBLE) {
                mainBinding.mainParent.setVisibility(View.VISIBLE);
            }
        }

    }

    @Override
    public void setContentView(int layoutResID) {
        mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
        super.setContentView(mainBinding.getRoot());
        SLog.d(TAG, "--setContentView--");
    }



    private void setInfoColor(String titleColor,String contentColor) {
        SLog.i(TAG, "setInfoColor---" + titleColor);
        if(TextUtils.isEmpty(titleColor)||TextUtils.isEmpty(contentColor)){
            return;
        }

        changeTextViewsFontColor(Color.parseColor(titleColor),Color.parseColor(contentColor));
    }

    public void changeTextViewsFontColor(int titleColor,int contentColor) {
        for (int i=1;i<7;i++){
            int titleId = getResources().getIdentifier("tv_title"+i, "id", getPackageName());
            int valueId = getResources().getIdentifier("tv_value"+i, "id", getPackageName());
            int unitId = getResources().getIdentifier("tv_unit"+i, "id", getPackageName());
            RogTextview tv_value = findViewById(valueId);
            RogTextview tv_unit = findViewById(unitId);
            TradeTextview tv_title = findViewById(titleId);
            SLog.i(TAG, "changeTextViewsFontColor---" + i);
//            if(i==6){
//                tv_title.setTextColor(contentColor);
//            }else {
//                tv_title.setTextColor(titleColor);
//            }
            tv_title.setTextColor(titleColor);
            tv_value.setTextColor(contentColor);
            tv_unit.setTextColor(contentColor);
        }
    }



    private HashMap<String,Integer> infoMap = new HashMap<>();
    private HashMap<Integer,String> infoIndexMap = new HashMap<>();
    private void setInfoValue(String key,String value,String unit){
        if (!infoMap.containsKey(key))return;
        int position = infoMap.get(key);
        int valueId = getResources().getIdentifier("tv_value"+position, "id", getPackageName());
        int unitId = getResources().getIdentifier("tv_unit"+position, "id", getPackageName());
        TextView tv_value = findViewById(valueId);
        TextView tv_unit = findViewById(unitId);
        /*if(position==6){
            if(key.equals("Date&Time")){
                mainBinding.tvUnit6.setVisibility(View.GONE);
                mainBinding.tvUnit62.setVisibility(View.VISIBLE);
                tv_unit = mainBinding.tvUnit62;
            }else {
                mainBinding.tvUnit6.setVisibility(View.VISIBLE);
                mainBinding.tvUnit62.setVisibility(View.GONE);
            }

        }*/

        tv_value.setText(value);
        tv_unit.setText(unit);

    }

    private void showInfo(ArrayList<String> infoArr) {

        for (int i = 0; i < infoArr.size(); i++) {
            String info = infoArr.get(i);
            SLog.i(TAG, "showInfo---" + info);
            int position = i+1;
            int textViewId = getResources().getIdentifier("tv_title"+position, "id", getPackageName());
            int layoutId = getResources().getIdentifier("value_layout_"+position, "id", getPackageName());
// 使用getIdentifier获取的ID来找到对应的TextView
            TextView title_tv = findViewById(textViewId);
            LinearLayout layout = findViewById(layoutId);
            infoIndexMap.put(position,info);
            if(TextUtils.isEmpty(info)){
                layout.setVisibility(View.INVISIBLE);
            }else {
                layout.setVisibility(View.VISIBLE);
                if(info.equals("Date&Time")){
                    Calendar calendar = Calendar.getInstance();
                    int month = calendar.get(Calendar.MONTH)+1; // 注意：月份是从0开始的
                    int day = calendar.get(Calendar.DAY_OF_MONTH);
                    calendar.setFirstDayOfWeek(Calendar.MONDAY); // 设置周一为一周的第一天
                    int dayOfWeekIndex = calendar.get(Calendar.DAY_OF_WEEK) - 1; // 获取星期几的索引（从0开始）
                    SLog.d(TAG,"dayOfWeekIndex--"+dayOfWeekIndex);
                    int year = calendar.get(Calendar.YEAR);
//                    title_tv.setText(monthS[month]+" "+day);
                    title_tv.setText(weeks[dayOfWeekIndex]+" "+day);
                }else {
                    title_tv.setText(subTitle.get(info));
                }
//                title_tv.setText(subTitle.get(info));
                infoMap.put(info,position);

            }

        }
        mainBinding.layoutContent1.setVisibility(View.VISIBLE);

    }

   private void goneAll(){
        mainBinding.layoutContent1.setVisibility(View.GONE);
        infoMap.clear();
       infoIndexMap.clear();
   }


    @Override
    public void onDoBrightness(int value) {
        SLog.d(TAG, "--onDoBrightness--" + value);
        Message message = new Message();
        message.what = MSG_REFRESH_BRIGIESS;
        message.obj = value;
        mainHandler.sendMessage(message);
    }


    @Override
    public void onDoPower(String event) {
        SLog.d(TAG, "--onDoPower--" + event);
        Message message = new Message();
        message.what = MSG_REFRESH_POWER;
        message.obj = event;
        mainHandler.sendMessage(message);
    }

    @Override
    public void onBlockScreen(boolean event) {
        SLog.d(TAG, "--onBlockScreen--" + event);
        Message message = new Message();
        message.what = MSG_REFRESH_BLOCKSCREEN;
        message.obj = event;
        mainHandler.sendMessage(message);
    }

    @Override
    public void onFileUpload(String path) {
        SLog.d(TAG, "--onFileUpload--" + path);
        Message message = new Message();
        message.what = MSG_REFRESH_FILE;
        message.obj = path;
        mainHandler.sendMessage(message);
    }

    @Override
    public void onRefreshUI(PcInfo pcInfo) {
        if (pcInfo != null) {
            Message message = new Message();
            message.what = MSG_REFRESH_UI;
            message.obj = pcInfo;
            mainHandler.sendMessage(message);

        }
    }

    @Override
    public void onDisConnect() {
        //goneAll();
        SLog.d(TAG, "--onDisConnect--");
        Message message = new Message();
        message.what = MSG_DISSCONNECT;
        mainHandler.sendMessage(message);
    }

    @Override
    public void onReConnect() {
        SLog.d(TAG, "--onReConnect--");
        Message message = new Message();
        message.what = MSG_RECONNECT;
        mainHandler.sendMessage(message);
    }

    @Override
    public void onConnected() {
        SLog.d(TAG, "--onConnected--");
        Message message = new Message();
        message.what = MSG_CONNECTED;
        mainHandler.sendMessage(message);


    }


    @Override
    public void refreshShowData(ArrayList<String> array) {
        if (array == null) {
            return;
        }
        Message message = new Message();
        message.what = MSG_REFRESH_SHOWINFO;
        message.obj = array;
        mainHandler.sendMessage(message);
    }

    @Override
    public void screenConfigChange(ScreenConfig config) {
        if (config == null) {
            return;
        }
        SLog.d(TAG, "--screenConfigChange--");
        Message message = new Message();
        message.what = MSG_REFRESH_CONFIG;
        message.obj = config;
        mainHandler.sendMessage(message);
    }

    @Override
    public void presetConfigChange(ScreenConfig config) {
        if (config == null) {
            return;
        }
        SLog.d(TAG, "--presetConfigChange--");
        Message message = new Message();
        message.what = MSG_PRESET_CONFIG;
        message.obj = config;
        mainHandler.sendMessage(message);
    }

    @Override
    public void nameTitleChange(String cpuName, String gpuName) {
        if (config == null) {
            return;
        }
        SLog.d(TAG, "--nameTitleChange--" + cpuName + "--" + gpuName);
        mCpuName = cpuName;
        mGpuName = gpuName;
        mainHandler.sendEmptyMessage(MSG_NAME_CHANGE);
    }

    @Override
    public void onWaterfallModeChange(boolean enble) {
        SLog.d(TAG, "--onWaterfallModeChange--" + enble);
        Message message = new Message();
        message.what = MSG_WATERFALLMODE_CHANGE;
        message.obj = enble;
        mainHandler.sendMessage(message);
    }

}